package com.example.demo.domain.exam;

import lombok.Data;

import java.io.Serializable;

@Data
public class Paging implements Serializable {

    private Long totalCount;

    private Long pageIndex;

    private Long pageSize;

    private boolean enableTotalCount;

    public Paging() {
        this(1L, 10L);
    }

    public Paging(Long pageIndex, Long pageSize) {
        this(pageIndex, pageSize, 0L);
    }

    public Paging(long pageIndex, long pageSize, long totalCount) {
        if (pageSize < 1L) {
            pageSize = 10L;
        }
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.pageIndex = pageIndex;
        this.enableTotalCount = true;
    }

    public Long getPageSize() {
        return this.pageSize == null || this.pageSize < 1L ? 10 : this.pageSize;
    }

    public Long getPageCount() {
        return this.totalCount < 1L ? 0L : Math.round(Math.ceil((double) this.totalCount / (double) this.pageSize));
    }

    public String toString() {
        return "Paging [totalCount=" + this.totalCount + ", pageIndex=" + this.pageIndex + ", pageSize=" + this.pageSize + ", enableTotalCount=" + this.enableTotalCount + "]";
    }

    public static Paging build(Long pageIndex, Long pageSize) {
        return new Paging(pageIndex, pageSize);
    }

    public static Paging build() {
        return new Paging();
    }
}
